<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
#login{
    width:300px;
    border:1px solid blue;
    line-height:40px;
    margin:0 auto;
    padding-left:50px;
    padding-top:15px;
    padding-bottom:15px;
    text-align:left;
    font-size:14px;
}
.error{
    color:red;
}
</style>
</head>
<body>
<?php 
  include "HeaderNav.html";
  
  // 如果设置了btnsubmit
  if (isset($_POST['btnsubmit'])) {
    // 如果点击了登陆按钮
    if (!empty( $_POST['stuno']) && $_POST['pwd']=="1234") {
      // 输入了账号密码
      // 设置7天后过期
      setcookie('stuno', $_POST['stuno'],time()+60*60*24*7);
      // 使用session保存登陆的学号信息
      session_start();
      $_SESSION['stuno'] = $_POST['stuno'];

      $backurl = 'index.php';
      if (isset($_GET['frompage'])) {
        $backurl=$_GET['frompage'].'.php';
      }
      echo "<script>window.location='{$backurl}'</script>";
    } else {
      echo "<script>window.alert('用户名或密码错误!')</script>";
    }
  }
?>
<h1>用户登录</h1>
<form action="" method="post">
<div id="login">
    <div>
学号：<input type="text" value="
<?php
  if (isset($_COOKIE['stuno'])) {
    echo $_COOKIE['stuno'];
  }
?>
" name="stuno"><span class="error">*</span>
    </div>
    <div>
密码：<input type="password" name="pwd"><span class="error">*</span>
    </div>
    <div style="margin-left:85px;">
        <input type="submit" name="btnsubmit" value="登录">
    </div>
</div>
</form>
<?php include "Footer.html" ?>
</body>
</html>
